<script setup>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
import { datetimeformat } from '@/utils/datetimeformat.js'

onMounted(() => {
  const myChart = echarts.init(document.getElementById('user'))
  myChart.setOption({
    title: {
      text: 'Stacked Line'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    toolbox: {
      feature: {
        saveAsImage: {}
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name: 'Email',
        type: 'line',
        stack: 'Total',
        data: [120, 132, 101, 134, 90, 230, 210]
      },
      {
        name: 'Union Ads',
        type: 'line',
        stack: 'Total',
        data: [220, 182, 191, 234, 290, 330, 310]
      },
      {
        name: 'Video Ads',
        type: 'line',
        stack: 'Total',
        data: [150, 232, 201, 154, 190, 330, 410]
      },
      {
        name: 'Direct',
        type: 'line',
        stack: 'Total',
        data: [320, 332, 301, 334, 390, 330, 320]
      },
      {
        name: 'Search Engine',
        type: 'line',
        stack: 'Total',
        data: [820, 932, 901, 934, 1290, 1330, 1320]
      }
    ]
  })
  const like = document.querySelector('#like')

  const likeChart = echarts.init(like)
  likeChart.setOption({
    title: {
      text: 'Referer of a Website',
      subtext: 'Fake Data',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads' }
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  })
})
//概览数据
const overview = ref({
  usernum: 0,
  addusernum: 0,
  publishedblog: 0,
  nopublishedblog: 0,
  good: 0
})
</script>
<template>
  <el-card class="overview">
    <template #header>
      <span>概览 {{ datetimeformat(new Date()) }}</span>
    </template>
    <el-row :gutter="10">
      <el-col :span="6"
        ><el-card class="info">
          <template #header> 用户数量 </template>
          <el-row>
            <el-col :span="24">新增用户：{{ overview.addusernum }}</el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div style="height: 20px"></div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">总用户：{{ overview.usernum }}</el-col>
          </el-row>
        </el-card></el-col
      >
      <el-col :span="6"
        ><el-card class="info">
          <template #header> 博客 </template>
          <el-row>
            <el-col :span="24">已发布：{{ overview.publishedblog }}</el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div style="height: 20px"></div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">草稿：{{ overview.nopublishedblog }}</el-col>
          </el-row>
        </el-card></el-col
      >
      <el-col :span="6"
        ><el-card class="info">
          <template #header>累计获赞 </template>
          <el-row>
            <el-col :span="24">
              <img src="@/icon/good.svg" class="good" />
              {{ overview.good }}
            </el-col>
          </el-row>
        </el-card></el-col
      >
      <el-col :span="6"><el-card class="info"></el-card></el-col>
    </el-row>
  </el-card>
  <div class="allchart">
    <el-card class="chart" id="user"> </el-card>
    <el-card class="chart" id="like"> </el-card>
  </div>
</template>
<style scoped>
* {
  margin: 0;
  padding: 0;
  border: 0;
}
.info {
  height: 153px;
}
.el-col {
  height: 100%;
  /* background-color: black; */
}
.el-card {
  margin-bottom: 15px;
}
.overview {
  height: 230px;
}
.chart {
  display: inline-block;
  width: 49%;
  height: 533px;
  margin-left: 8px;
}
.allchart {
  display: inline;
}
.good {
  width: 50px;
  height: 50px;
}
</style>
